package com.jctrip.hotel.source.xxl.greentree;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jctrip.hotel.common.constant.XxlJobNameConstant;
import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.domain.dao.HtSourceInfoDao;
import com.jctrip.hotel.domain.entity.HtSourceInfo;
import com.jctrip.hotel.source.model.CommonJobParam;
import com.jctrip.hotel.source.service.greentree.GreenTreeTaskService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author：Haruhi
 * @description:
 * @Date：2023/9/4 11:16
 * @Package：com.jctrip.hotel.source.xxl.greentree.thread
 * @Project：hotel-main
 */
@Slf4j
@Component
public class SyncGreenTreeHotelInfoTaskFastPushXxlJob extends IJobHandler {
    @Resource
    private GreenTreeTaskService greenTreeTaskService;

    @Resource
    private HtSourceInfoDao htSourceInfoDao;


    @Override
    @XxlJob(XxlJobNameConstant.SYNC_GREENTREE_INFO_PUSH)
    public void execute() throws Exception {
        XxlJobHelper.log(XxlJobNameConstant.SYNC_GREENTREE_INFO_PUSH + "xxl job strat");
        try {
            CommonJobParam greentreeJobParam = JsonUtil.toObject(CommonJobParam.class, XxlJobHelper.getJobParam());
            HtSourceInfo htSourceInfo =
                    htSourceInfoDao.selectOne(new LambdaQueryWrapper<HtSourceInfo>().eq(HtSourceInfo::getSourceId,
                            greentreeJobParam.getSourceId()));
            if (htSourceInfo == null) {
                return;
            }
            greenTreeTaskService.syncGreenTreeHotelIdListTaskFastPush(htSourceInfo.getSourceAppId());
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }

        XxlJobHelper.log(XxlJobNameConstant.SYNC_GREENTREE_INFO_PUSH + "xxl job end");
    }
}
